#!/usr/bin/env node

const mysql = require('mysql2/promise');

//创建连接
let con = mysql.createPool({
  host: 'localhost',
  user: 'root',
  password: 'ddd',
  database: 'test'
});

//getAreas();

async function getAreas() {
  var sql = 'select * from areas';

  //查询
  let [result] = await con.execute(sql);
  console.log(result);
}
async function addArea(areaName) {
  var sql = `insert into areas(area_name) values('${areaName}')`;
  let [result] = await con.execute(sql);
  return result;
}
async function updateArea(oldname, newname) {
  var sql = `update areas set area_name='${newname}' where area_name='${oldname}'`;
  let [result] = await con.execute(sql);
  return result;
}
async function deleteArea(areaname) {
  var sql = `delete from areas where area_name = '${areaname}'`;
  let [result] = await con.execute(sql);
  return result;
}
(async function() {
  //await addArea('啊哈');
  //await getAreas();
  //await deleteArea('啊哈');
  await updateArea('大陆', '大陆aaaaaaa');
  await getAreas();
})();
